package com.android.openapp.data;

import java.util.LinkedHashMap;

import org.json.JSONArray;
import org.json.JSONObject;

import android.graphics.Color;

import com.socrata.api.HttpConnection;
import com.socrata.data.View.Row;

public class Fiera extends Place{
	
	
	Row fiera;
	
	LinkedHashMap<String, Object> coord;
	
	public Fiera(Row fier) {
		
		super.setMetadata(Place.listmetadati.get(5));
		super.setRow(fier);
		setBcolor(Color.GREEN);
		super.setMapData(super.getRow().getDataFieldsForSerialization());
		
		Double lon = new Double(0);
        Double lat = new Double(0);

        try {
        	
        	
            
            JSONObject jsonObject=HttpConnection.getLocationInfo(getAddress());
            
			lon = ((JSONArray)jsonObject.get("results")).getJSONObject(0)
                .getJSONObject("geometry").getJSONObject("location")
                .getDouble("lng");

            lat = ((JSONArray)jsonObject.get("results")).getJSONObject(0)
                .getJSONObject("geometry").getJSONObject("location")
                .getDouble("lat");

        } catch (Exception e) {
            e.printStackTrace();

        }
        super.setCoord(lat, lon);
		
		
	}
	
	@Override
	public String getDenominazione() {
		// TODO Auto-generated method stub
		return super.getStringValue("MANIFESTAZIONE");
	}

	@Override
	public String getTipologia() {
		// TODO Auto-generated method stub
		return super.getStringValue("QUALIFICA")+ "-" +super.getStringValue("DATA_INIZIO")+ 
				" -> "+super.getStringValue("DATA_FINE") ;
	}

	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String getAddress() {
		StringBuilder builder = new StringBuilder();
		
		if (getStringValue("LOCALITA") != null){
			builder.append(getStringValue("LOCALITA")).append(", ");
		}
			builder.append(getStringValue("PROVINCIA"));
		return builder.toString();
	}

	@Override
	public String getContactInfo() {
		return null; //non abbiamo info a disposizione
	}
	
}
